from model.explanatory_dictionary import ExplanatoryDictionary
from model.dictionaryinfo import DictionaryInfo
from model.dictionary import Dictionary
import codecs

if __name__ == "__main__":
    di = DictionaryInfo.parse_dictionaries_metadata()
    all_files = [info.file_name for info in di]
    whole_dict = Dictionary(all_files)
    articles = ExplanatoryDictionary()
    used_words = [word.text for word in whole_dict.dictionary_words if word.text in articles.dictionary]
    selected_dict = {}
    for word in used_words:
	selected_dict[word]=articles.dictionary[word]
    with codecs.open('out.dct', encoding='utf8', mode='w') as f:
	f.write('^')
	for word in selected_dict:
	    f.write('$')
	    f.write(word)
	    f.write('^')
	    f.write(selected_dict[word])
	f.write('$')
